<template>
  <router-view></router-view>
</template>
<script setup>
import { ref, onMounted, computed } from "vue";
import { useRoute } from "vue-router";
import { useRouter } from "vue-router";
import { useStore } from "vuex";
import { configshop,userInfo2123 } from "./api/index";
import a from "./i18n/A_World";
console.log(a);
const route = useRoute();
const router = useRouter();
const Store = useStore();

const goToHome = () => {
  router.push("/");
};

// 移除这里的直接调用
// Store.dispatch('initializeAuth')
// Store.dispatch('initializeLanguage')

const userAgent = navigator.userAgent || navigator.vendor || window.opera;
Store.state.isMobile =
  /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(
    userAgent
  );

const isMobile = ref();
isMobile.value = Store.state.isMobile;

// 计算属性获取登录状态和语言状态
const isLoggedIn = computed(() => Store.getters.isLoggedIn);
const userInfo = computed(() => Store.getters.userInfo);
const currentLanguage = computed(() => Store.getters.currentLanguage);
const isChinese = computed(() => Store.getters.isChinese);
const isEnglish = computed(() => Store.getters.isEnglish);

const configshopz = ref({});
const activeNames = ref([]);
const showTop = ref(false);
const value1 = ref();

console.log(window.innerWidth);
console.log(window.innerHeight);
let ls = JSON.parse(localStorage.getItem('userInfo'))
console.log('ls',ls);
if(ls){
  Store.state.userInfoK = ls;
}

const offset1 = ref({ x: window.innerWidth - 80, y: window.innerHeight - 100 });
const offset2 = ref({ x: window.innerWidth - 60, y: window.innerHeight - 100 });
const tab = ref(["中文/English"]);

// 获取当前语言的文本
const getCurrentText = (chineseText, englishText) => {
  if (!chineseText || !englishText) return chineseText || englishText || "";
  return currentLanguage.value === "zh" ? chineseText : englishText;
};

const getData = async () => {
  let info = await configshop();
  configshopz.value = info.data;
  // let info2 = await userInfo2123()
  
  // Store.state.userInfoK = info2.data

  // 同时更新store中的shopInfo
  Store.dispatch("setShopInfo", {
    shopName: info.data.shop_title,
    shopData: info.data,
  });
};

// 导航方法
const goToLogin = () => {
  router.push("/login");
};

const goToProfile = () => {
  router.push("/profile");
};

const onClick = () => {
  window.open(configshopz.value.kefu_url);
};

const zdyUrl = () => {
  window.open(configshopz.value.zdy_url);
};

const go = (index) => {
  showTop.value = false;
  Store.state.active = index;
  switch (index) {
    case 0:
      // 语言切换
      Store.dispatch("toggleLanguage");
      break;
    case 1:
      router.push("/survey");
      break;
    case 2:
      router.push("/rewards");
      break;
  }
};

onMounted(() => {
  // 在组件挂载后初始化store
  Store.dispatch("initializeAuth");
  Store.dispatch("initializeLanguage");
  Store.dispatch("initializeShopInfo");
  getData();
  
  // 禁止双击放大
  preventDoubleTapZoom();
});

// 禁止双击放大的函数
const preventDoubleTapZoom = () => {
  let lastTouchEnd = 0;
  
  // 阻止双击缩放
  document.addEventListener('touchend', (event) => {
    const now = (new Date()).getTime();
    if (now - lastTouchEnd <= 300) {
      event.preventDefault();
    }
    lastTouchEnd = now;
  }, false);
  
  // 阻止双指缩放
  document.addEventListener('gesturestart', (event) => {
    event.preventDefault();
  });
  
  document.addEventListener('gesturechange', (event) => {
    event.preventDefault();
  });
  
  document.addEventListener('gestureend', (event) => {
    event.preventDefault();
  });
  
  // 阻止鼠标双击缩放
  document.addEventListener('dblclick', (event) => {
    event.preventDefault();
  });
};
</script>

<style scoped lang="scss">
:deep(.el-collapse-item__wrap) {
  background: none !important;
}
.header {
  height: 0.5rem;
  position: fixed;
  padding: 0 0.5rem;
  left: 0;
  right: 0;
  top: 0;
  z-index: 999;
  background: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: rgba(0, 0, 0, 0.15) 0px 0.0008rem 4px 0.0008rem;

  .l {
    width: 25%;
    display: flex;
    // justify-content: flex-end;
    align-items: center;
    font-size: 0.1rem;

    .logo {
      width: 0.3rem;
      height: 0.3rem;
    }

    .text {
      margin-left: 0.08rem;
      font-size: 0.1rem;
      font-weight: 500;

      .text1 {
        letter-spacing: 0.03rem;
        margin-bottom: 0.03rem;
      }
    }
  }

  .c {
    width: 65%;
    display: flex;
    justify-content: flex-end;
    font-size: 0.1rem;
    color: rgb(121, 187, 255);
    margin-left: 10%;

    .c_text:hover {
      color: rgb(83, 168, 255);
      cursor: pointer;
    }
  }

  .r {
    width: 10%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.1rem;
    color: rgb(83, 168, 255);
    .x {
      width: 0.0008rem;
      height: 0.08rem;
      background: #d8d8d8;
      margin: 0 0.08rem;
    }
  }
}

.header2 {
  height: 1.5rem;
  position: fixed;
  padding: 0 0.5rem;
  left: 0;
  right: 0;
  top: 0;
  z-index: 999999;
  background: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: rgba(0, 0, 0, 0.15) 0px 0.0008rem 4px 0.0008rem;

  .l {
    width: 100%;
    display: flex;
    align-items: center;
    font-size: 0.5rem;
    color: #222;

    img {
      width: 1rem;
      margin-right: 0.05rem;
    }
  }

  .r {
    display: flex;
    justify-content: flex-end;
    overflow: hidden;
    font-size: 0.5rem;
    color: #222;

    img {
      width: 1rem;
    }

    .tc {
      width: 30vw;
      position: absolute;
      background: #fff;
      right: 0;
      top: 1.5rem;
      text-align: center;

      .tc_item {
        padding: 0.1rem 0;
      }

      .tc_item:hover {
        background: #409eff;
        color: #fff;
      }
    }
  }
}

.dbt {
  background: rgb(51, 89, 143);
  color: #fff;
  padding: 0.3rem 1rem;

  .t {
    display: flex;
    padding-bottom: 0.2rem;
    border-bottom: 0.01rem solid hsla(0, 0%, 100%, 0.2);

    .c_item {
      width: 25%;
      font-size: 0.1rem;
      margin-right: 0.5rem;
    }
  }

  .t2 {
    margin-top: 0.2rem;

    .c_item_i {
      display: flex;
      align-items: center;
      margin-bottom: 0.1rem;

      img {
        width: 0.2rem;
        height: 0.2rem;
        margin-right: 0.05rem;
      }
    }

    .imgbox {
      width: 0.6rem;
      height: 0.6rem;

      img {
        width: 100%;
        height: 100%;
      }
    }
  }

  .tsm {
    padding: 0.2rem 1rem 0 1rem;
    text-align: center;
    font-size: 0.1rem;
  }
}

.dbt2 {
  background: rgb(51, 89, 143);
  color: #fff;
  padding: 0.3rem 1rem;

  .c_item {
    img {
      width: 2rem;
    }
    .c_item_i {
      width: 100%;
      display: flex;
      align-items: center;
      margin-bottom: 0.3rem;
      img {
        width: 0.8rem;
        margin-right: 0.5rem;
      }
    }
  }

  .tsm {
    padding: 0.2rem 0;
    text-align: center;
    font-size: 0.3rem;
  }

  :deep(.el-collapse-item__header) {
    background: none;
    color: #fff;
    border: none;
  }
  :deep(.el-collapse-item__content) {
    background: none;
    color: #fff;
  }
  :deep(.el-collapse-item__arrow) {
    color: #fff;
  }
}
</style>
